﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI.WebControls;

namespace Common
{
    public class Str
    {
        public static string FilterSql(string Str)
        {
            Str = Str.ToLower();
            Str = Str.Replace("'", "");
            Str = Str.Replace("insert", "");
            Str = Str.Replace("update", "");
            Str = Str.Replace("delete", "");
            return Str;
        }
        /// <summary>
        ///  使用指定正则进行验证 
        /// </summary>
        /// <param name="regexString">正则表达式</param>
        /// <param name="validateString">待验证数据</param>
        /// <returns></returns>
        public static bool RegexValidate(string regexString, string validateString)
        {
            if (validateString != "")
            {
                Regex regex = new Regex(regexString);
                return regex.IsMatch(validateString.Trim());
            }
            else
            {
                return false;
            }

        }
        public static string GetGuid()
        {
            string str = Guid.NewGuid().ToString();
            //str = str.Replace("-", "");
            return str;
        }

        //得到当前月(如得到的月份小于2位数,则在前于加0)
        public static string getCurentMonth()
        {
            string strMonth = DateTime.Now.Month.ToString();
            if (strMonth.Length < 2)
            {
                strMonth = "0" + strMonth;
            }
            return strMonth;
        }


        public static bool IsInt32(string strNumeric)
        {
            bool bolResult = false;

            try
            {
                Convert.ToInt32(strNumeric);
                bolResult = true;
            }
            catch
            {
                bolResult = false;
            }

            return bolResult;
        }


        /// <summary>
        /// 验证输入的日期是否为 时间(时:分:秒)
        /// </summary>
        /// <param name="validateString"></param>
        /// <returns></returns>
        public static bool IsTime(string validateString)
        {
            return RegexValidate("^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$", validateString);
        }







        /// <summary>
        /// 验证输入的日期是否为 时间(时)
        /// </summary>
        /// <param name="validateString"></param>
        /// <returns></returns>
        public static bool IsHour(string validateString)
        {
            return RegexValidate("^([0-1]?[0-9]|2[0-3])$", validateString);
        }
        /// <summary>
        /// 是否为IP地址
        /// </summary>
        /// <param name="validateString"></param>
        /// <returns></returns>
        public static bool IsIp(string validateString)
        {
            return RegexValidate(@"((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))", validateString);
        }





        public static bool IsDouble(string strNumeric)
        {
            bool bolResult = false;

            try
            {
                Convert.ToDouble(strNumeric);
                bolResult = true;
            }
            catch
            {
                bolResult = false;
            }

            return bolResult;
        }

        public static bool IsDecimal(string strNumeric)
        {
            bool bolResult = false;

            try
            {
                Convert.ToDecimal(strNumeric);
                bolResult = true;
            }
            catch
            {
                bolResult = false;
            }

            return bolResult;
        }


        public static bool IsDateTime(string strDatetime)
        {
            bool bolResult = false;

            try
            {
                Convert.ToDateTime(strDatetime);
                bolResult = true;
            }
            catch
            {
                bolResult = false;
            }

            return bolResult;
        }

        public static string GetValidDate(string strDate, int mode)
        {
            string m_strDate = strDate;

            if (IsDateTime(m_strDate) == true)
            {
                DateTime m_dtDate = Convert.ToDateTime(m_strDate);

                if ((mode > 9) || (mode < 1)) { mode = 1; }

                switch (mode)
                {
                    case 1:
                        m_strDate = m_dtDate.ToString("yyyy-MM-dd HH:mm:ss");
                        break;
                    case 2:
                        m_strDate = m_dtDate.ToString("yyyy-MM-dd");
                        break;
                    case 3:
                        m_strDate = m_dtDate.ToString("HH:mm:ss");
                        break;
                    case 4:
                        m_strDate = m_dtDate.ToString("yyMMdd");
                        break;
                    case 5:
                        m_strDate = m_dtDate.ToString("yyyyMMddHHmmss");
                        break;
                    case 6:
                        m_strDate = m_dtDate.ToString("yyyy年MM月dd日 HH:mm:ss");
                        break;
                    case 7:
                        m_strDate = m_dtDate.ToString("yyyy年MM月dd日");
                        break;
                    case 8:
                        m_strDate = m_dtDate.ToString("yyyy年MM月");
                        break;
                    case 9:
                        m_strDate = m_dtDate.ToString("yyyy-MM");
                        break;
                    default:
                        m_strDate = m_dtDate.ToString("yyyy-MM-dd HH:mm:ss");
                        break;
                }
            }

            return m_strDate;
        }

        public static string GetValidDateBegin(string strDateBegin)
        {
            string m_strDate = strDateBegin;

            if (IsDateTime(m_strDate) == true)
            {
                DateTime m_dtDate = Convert.ToDateTime(m_strDate);

                m_strDate = m_dtDate.ToString("yyyy") + "-" + m_dtDate.ToString("MM") + "-" + m_dtDate.ToString("dd") + " 00:00:00";
            }

            return m_strDate;
        }

        public static string GetValidDateEnd(string strDateEnd)
        {
            string m_strDate = strDateEnd;

            if (IsDateTime(m_strDate) == true)
            {
                DateTime m_dtDate = Convert.ToDateTime(m_strDate);

                m_strDate = m_dtDate.ToString("yyyy") + "-" + m_dtDate.ToString("MM") + "-" + m_dtDate.ToString("dd") + " 23:59:59";
            }

            return m_strDate;
        }

        public static string GetNumericFormat(string strNumeric, int intValidNumber)
        {
            double dblDouble = 0.00F;

            try
            {
                if (IsDouble(strNumeric) == true)
                {
                    dblDouble = Convert.ToDouble(strNumeric);
                }
            }
            catch
            {

            }

            return string.Format("{0:F" + intValidNumber.ToString() + "}", dblDouble);
        }

        /// <summary>
        ///得到指定字符在字符串集中的数量
        /// </summary>
        /// <param name="SourceString">字符串集</param>
        /// <param name="MyTag">指定字符标签</param>
        /// <returns>返回数量</returns>
        public static int GetTagNum(string SourceString, string MyTag)
        {
            int TempNum = 0;
            int SSLength = SourceString.Length;
            int TagLength = MyTag.Length;
            string TempGetTag;
            int StartIndex = 0;
            for (int LoopN = 0; LoopN < SSLength; LoopN++)
            {
                if ((SSLength - StartIndex) >= TagLength)
                {
                    TempGetTag = SourceString.Substring(StartIndex, TagLength);
                    if (TempGetTag == MyTag)
                    {
                        TempNum = TempNum + 1;
                    }
                    StartIndex = StartIndex + 1;
                }
            }
            return TempNum;
        }


        /// <summary>
        ///得到指定字符串的的反转字符串
        /// </summary>
        /// <param name="SourceString">指定字符串</param>
        /// <returns>返回反转后的字符串</returns>
        public static string GetInvString(string SourceString)
        {
            string TempString = "";
            int SSLength = SourceString.Length;
            string TempGetTag;
            int StartIndex = 0;
            for (int LoopN = 0; LoopN < SSLength; LoopN++)
            {
                if ((SSLength - StartIndex) >= 1)
                {
                    TempGetTag = SourceString.Substring(StartIndex, 1);
                    TempString = TempGetTag + TempString;
                    StartIndex = StartIndex + 1;
                }
            }
            return TempString;
        }



        /// <summary>
        ///得到随机的int数
        /// </summary>
        /// <param name="MinInt">随机序列的最小值</param>
        /// <param name="MaxInt">随机序列的最大值</param>
        /// <returns>返回得到的随机的int数</returns>
        public static int GetRandomInt(int MinInt, int MaxInt)
        {
            int MyRnd = 1;
            //生成一个随机函数(以当前时间为随机种子,每次生成不同的随机数列)
            Random MyRandom = new System.Random(unchecked((int)DateTime.Now.Ticks));
            MyRnd = MyRandom.Next(MinInt, MaxInt);

            return MyRnd;
        }

        /// <summary>
        ///得到随机的颜色代码
        /// </summary>
        /// <returns>返回得到的随机的颜色代码</returns>
        public static string GetRandomColor()
        {
            int Length = 6;
            Random MyRandom = new Random();
            byte[] MyByte = new byte[Length];

            int LoopN;
            for (LoopN = 0; LoopN < Length; LoopN++)
            {
                int MyInt = 0;
                while (!((MyInt >= 48 && MyInt <= 57) || (MyInt >= 65 && MyInt <= 70)))
                {
                    MyInt = MyRandom.Next(48, 125);
                }
                MyByte[LoopN] = (byte)MyInt;
            }

            return new string(UnicodeEncoding.ASCII.GetChars(MyByte));
        }

        /// <summary>
        ///得到随机的字符串
        /// </summary>
        /// <param name="Length">产生字符串的长度</param>
        /// <returns>返回得到的随机的字符串</returns>
        public static string GetRandomString(int Length)
        {
            Random MyRandom = new Random();
            byte[] MyByte = new byte[Length];

            int LoopN;
            for (LoopN = 0; LoopN < Length; LoopN++)
            {
                int MyInt = 0;
                //while 后的条件用来限定密码的字符集，本例中是限定为大小写字母
                while (!((MyInt >= 48 && MyInt <= 57) || (MyInt >= 65 && MyInt <= 90) || (MyInt >= 97 && MyInt <= 122)))
                {
                    MyInt = MyRandom.Next(48, 125);
                }
                MyByte[LoopN] = (byte)MyInt;
            }

            return new string(UnicodeEncoding.ASCII.GetChars(MyByte));
        }

        /// <summary>
        ///得到随机的字符串
        /// </summary>
        /// <param name="Length">产生字符串的长度</param>
        /// <returns>返回得到的随机的字符串</returns>
        public static string GetRandomNumericString(int Length)
        {
            Random MyRandom = new Random();
            byte[] MyByte = new byte[Length];

            int LoopN;
            for (LoopN = 0; LoopN < Length; LoopN++)
            {
                int MyInt = 0;
                //while 后的条件用来限定密码的字符集，本例中是限定为大小写字母
                while (!(MyInt >= 48 && MyInt <= 57))
                {
                    MyInt = MyRandom.Next(48, 125);
                }
                MyByte[LoopN] = (byte)MyInt;
            }

            return new string(UnicodeEncoding.ASCII.GetChars(MyByte));
        }

        /// <summary>
        ///得到用Htm换行后的字符串
        /// </summary>
        /// <param name="LineWordNum">每行显示的单词数量</param>
        /// <param name="SourceText">要进行换行格式化的源文本</param>
        /// <returns>返回得到用Htm换行后的字符串</returns>
        public static string GetWrapText(string SourceText, int LineWordNum)
        {
            int Length = SourceText.Length;
            if (LineWordNum >= Length)
            {
                return SourceText;
            }

            int LineNum = (Length / LineWordNum) + 1;
            string CLineStr = "";
            string ResultStr = "";
            int CStartIndex = 0;
            int CLineLength = 0;
            for (int LoopNum = 0; LoopNum < LineNum; LoopNum++)
            {
                CStartIndex = LoopNum * LineWordNum;
                CLineLength = LineWordNum;

                if ((Length - CStartIndex) < LineWordNum)
                {
                    CLineLength = Length - CStartIndex;
                }

                CLineStr = SourceText.Substring(CStartIndex, CLineLength) + "<br>";
                ResultStr = ResultStr + CLineStr;
            }
            return ResultStr;
        }

        /// <summary>
        ///得到用Htm插入标签字符后的字符串
        /// </summary>
        /// <param name="LineWordNum">每行显示的单词数量</param>
        /// <param name="SourceText">要进行换行格式化的源文本</param>
        /// <param name="TagString">要插入的标签文本</param>
        /// <returns>返回得到用Htm插入标签字符后的字符串</returns>
        public static string GetInTagText(string SourceText, int LineWordNum, string TagString)
        {
            int Length = SourceText.Length;
            if (LineWordNum >= Length)
            {
                return SourceText;
            }

            int LineNum = (Length / LineWordNum) + 1;
            string CLineStr = "";
            string ResultStr = "";
            int CStartIndex = 0;
            int CLineLength = 0;
            for (int LoopNum = 0; LoopNum < LineNum; LoopNum++)
            {
                CStartIndex = LoopNum * LineWordNum;
                CLineLength = LineWordNum;

                if ((Length - CStartIndex) < LineWordNum)
                {
                    CLineLength = Length - CStartIndex;
                }

                CLineStr = SourceText.Substring(CStartIndex, CLineLength) + TagString;
                ResultStr = ResultStr + CLineStr;
            }
            return ResultStr;
        }

        /// <summary>
        ///得到某标签字符在某标签字符串中的位置
        /// </summary>
        /// <param name="Tag">标签字符(限一个字符)</param>
        /// <param name="AllTagString">标签字符串(限单字符序列)</param>
        /// <returns>返回某标签字符在某标签字符串中的位置，如得到失败则返回0</returns>
        public static int GetTagPosition(string Tag, string AllTagString)
        {
            string ts;
            int TempPosition = 0;
            for (int N = 0; N <= AllTagString.Length - 1; N++)
            {
                ts = AllTagString.Substring(N, 1);
                if (Tag == ts)
                {
                    TempPosition = N;
                    break;
                }
            }
            return TempPosition;
        }

        /// <summary>
        ///判断某标签字符在某标签字符串中
        /// </summary>
        /// <param name="Tag">标签字符(限一个字符)</param>
        /// <param name="AllTagString">标签字符串(限单字符序列)</param>
        /// <returns>返回true或false</returns>
        public static bool IsTagInTagString(string Tag, string AllTagString)
        {
            bool br = false;
            string ts = "";
            for (int N = 0; N <= AllTagString.Length - 1; N++)
            {
                ts = AllTagString.Substring(N, 1);
                if (Tag == ts)
                {
                    br = true;
                    break;
                }
            }
            return br;
        }

        /// <summary>
        ///判断某标签字符在某标签字符串中
        /// </summary>
        /// <param name="TagString">标签字符(限一个字符)</param>
        /// <param name="AllTagString">标签字符串(限单字符序列)</param>
        /// <returns>返回true或false</returns>
        public static bool IsTagStringInTagString(string TagString, string AllTagString)
        {
            bool br = false;
            string ts = "";
            for (int N = 0; N <= AllTagString.Length - TagString.Length; N++)
            {
                ts = AllTagString.Substring(N, TagString.Length);
                if (TagString == ts)
                {
                    br = true;
                    break;
                }
            }
            return br;
        }

        /// <summary>
        ///将十六进制转换成十进制数格式
        /// </summary>
        /// <param name="HexNumberString">十六进制数</param>
        /// <returns>返回转换后的十进制数</returns>
        public static int GetHexToDec(string HexNumberString)
        {
            return int.Parse(HexNumberString, System.Globalization.NumberStyles.AllowHexSpecifier);
        }

        /// <summary>
        ///将字符编码改成ASCII码
        /// </summary>
        /// <param name="CN">将要编码的字符串</param>
        /// <returns>返回ASCII码</returns>
        public static string Chr(int N)
        {
            return Convert.ToChar(N).ToString();
        }

        /// <summary>
        ///将ASCII码改成字符编码
        /// </summary>
        /// <param name="S">将要编码的字符串</param>
        /// <returns>返回字符编码</returns>
        public static int Asc(string S)
        {
            return Convert.ToInt16(Convert.ToChar(S));
        }

        /// <summary>
        ///将input格式的字符串还原成page格式
        /// </summary>
        /// <param name="S">将要还原的字符串</param>
        /// <returns>返回page格式的字符串</returns>
        public static string GetTxtToHtm(string S)
        {
            string TempS = S;

            TempS = TempS.Replace("&", "&amp;");
            TempS = TempS.Replace("'", "''");
            TempS = TempS.Replace("\"", "&quot;");
            TempS = TempS.Replace("<", "&lt");
            TempS = TempS.Replace(">", "&gt");
            TempS = TempS.Replace("/n", "<br>");
            TempS = TempS.Replace(Convert.ToChar(13).ToString(), "<br>");
            TempS = TempS.Replace(Convert.ToChar(32).ToString(), "&nbsp;");
            TempS = TempS.Replace(" ", "&nbsp;");
            TempS = TempS.Replace("[[", "<");
            TempS = TempS.Replace("]]", ">");

            return TempS;
        }

        /// <summary>
        ///将input格式的字符串还原成page格式
        /// </summary>
        /// <param name="S">将要还原的字符串</param>
        /// <returns>返回page格式的字符串</returns>
        public static string GetHtmToTxt(string S)
        {
            string TempS = S;

            TempS = TempS.Replace("&amp;", "&");
            TempS = TempS.Replace("''", "'");
            TempS = TempS.Replace("&quot;", "\"");
            TempS = TempS.Replace("<br>", "\n");
            TempS = TempS.Replace("&gt;", ">");
            TempS = TempS.Replace("&lt;", "<");
            TempS = TempS.Replace("&nbsp;", " ");
            TempS = TempS.Replace("&quot;", "\"");

            return TempS;
        }

        /// <summary>
        ///得到当前的时间
        /// </summary>
        /// <param name="mode">选择时间的模式</param>
        /// <returns>返回时间</returns>
        public static string GetDateTime(int mode)
        {
            string NowDateTime = "";
            string strDate = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            if (IsDateTime(strDate) == true)
            {
                System.DateTime MyDateTime = Convert.ToDateTime(strDate);
                if ((mode > 9) || (mode < 1)) { mode = 1; }

                switch (mode)
                {
                    case 1:
                        NowDateTime = MyDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                        break;
                    case 2:
                        NowDateTime = MyDateTime.ToString("yyyy-MM-dd");
                        break;
                    case 3:
                        NowDateTime = MyDateTime.ToString("HH:mm:ss");
                        break;
                    case 4:
                        NowDateTime = MyDateTime.ToString("yyMMdd");
                        break;
                    case 5:
                        NowDateTime = MyDateTime.ToString("yyyyMMddHHmmss");
                        break;
                    case 6:
                        NowDateTime = MyDateTime.ToString("yyyy年MM月dd日 HH:mm:ss");
                        break;
                    case 7:
                        NowDateTime = MyDateTime.ToString("yyyy年MM月dd日");
                        break;
                    case 8:
                        NowDateTime = MyDateTime.ToString("yyyy年MM月");
                        break;
                    case 9:
                        NowDateTime = MyDateTime.ToString("yyyy-MM");
                        break;
                    default:
                        NowDateTime = MyDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                        break;
                }
            }

            return NowDateTime;
        }

        /// <summary>
        ///得到时间的格式化字符串
        /// </summary>
        /// <param name="mode">选择时间的模式</param>
        /// <returns>返回时间</returns>
        public static string GetFormatDateTime(string strDate)
        {
            string strResult = strDate;

            if (IsDateTime(strDate) == true)
            {
                strResult = Convert.ToDateTime(strDate).ToString("yyyy-MM-dd");
            }

            return strResult;
        }

        /// <summary>
        ///取得两个时间相差的秒数
        /// </summary>
        /// <param name="OldDatatime">输入字符类型的旧时间</param>
        /// <param name="NewDateTime">输入字符类型的新时间</param>
        /// <returns>返回两个时间相差的秒数</returns>
        public static int GetDiffDateTime(string OldDatatime, string NewDateTime)
        {
            DateTime ODT = ((IConvertible)OldDatatime).ToDateTime(System.Globalization.DateTimeFormatInfo.CurrentInfo);
            DateTime NDT = ((IConvertible)NewDateTime).ToDateTime(System.Globalization.DateTimeFormatInfo.CurrentInfo);
            TimeSpan DateTimeDiff = NDT.Subtract(ODT);
            int DateDiffSeconds = (DateTimeDiff.Days * 86400) + (DateTimeDiff.Hours * 3600) + (DateTimeDiff.Minutes * 60) + (DateTimeDiff.Seconds);
            return DateDiffSeconds;
        }

        /// <summary>
        ///克隆指定字符的个数
        /// </summary>
        /// <param name="strString">指定字符</param>
        /// <param name="intLength">克隆个数</param>
        /// <returns>字符串</returns>
        public static string GetNumberString(string strString, int intLength)
        {
            string strResult = "";

            for (int N = 1; N <= intLength; N++)
            {
                strResult = strResult + strString;
            }

            return strResult;
        }

        /// <summary>
        ///判断某指定字符是否在另一字符数组里面
        /// </summary>
        /// <param name="strTagString">指定字符</param>
        /// <param name="strArrayString">以","号分隔字符</param>
        /// <returns>返回bool</returns>
        public static bool IsInArrayString(string strTagString, string strArrayString)
        {
            bool bolResult = false;

            if (strTagString == strArrayString)
            {
                bolResult = true;
            }
            else
            {
                string[] arrArray = strArrayString.Split(',');

                for (int N = 0; N < arrArray.Length; N++)
                {
                    if (arrArray[N].ToString() == strTagString)
                    {
                        bolResult = true;
                    }
                }
            }

            return bolResult;
        }


        /// <summary>
        /// 进制转换函数 讲10进制转换成2.8.16
        /// </summary>
        /// <param name="Int10">原10进制数据</param>
        /// <param name="Jzmc">进制数</param>
        /// <param name="length">返回字符长度</param>
        /// <param name="spaceChar">前补字符char</param>
        /// <returns></returns>
        public static string Convert10To(int Int10, int Jzmc, int length, char spaceChar)
        {
            string result = Convert.ToString(Int10, Jzmc).ToUpper();
            int x_int = length - result.Length;//字符长度相差
            string x_str = "";
            for (int i = 0; i < x_int; i++)
            {
                x_str += spaceChar;
            }
            return x_str + result;
        }


        /// <summary>
        ///得到字符串中除去某些字符后的字符集
        /// </summary>
        /// <param name="strArrayString">以","号分隔字符</param>
        /// <param name="strExorcizeString">去除字符</param>
        /// <returns>返回字符集</returns>
        public static string GetExorcizeArrayString(string strArrayString, string strExorcizeString)
        {
            string strResult = "";

            string[] arrArray = strArrayString.Split(',');

            for (int N = 0; N < arrArray.Length; N++)
            {
                if (arrArray[N].ToString() != strExorcizeString)
                {
                    if (N == 0)
                    {
                        strResult = arrArray[N].ToString();
                    }
                    else
                    {
                        strResult = strResult + "," + arrArray[N].ToString();
                    }
                }
            }
            return strResult;
        }

        /// <summary>
        ///Base64加密
        /// </summary>
        /// <returns>返回string</returns>
        public static string EncodeBase64(string s)
        {
            string strResult = "";

            if ((s != null) && (s != ""))
            {
                strResult = Convert.ToBase64String(System.Text.ASCIIEncoding.Default.GetBytes(s));
            }

            return strResult;
        }

        /// <summary>
        ///Base64解密
        /// </summary>
        /// <returns>返回string</returns>
        public static string DecodeBase64(string s)
        {
            string strResult = "";

            if ((s != null) && (s != ""))
            {
                strResult = System.Text.ASCIIEncoding.Default.GetString(Convert.FromBase64String(s));
            }

            return strResult;
        }





        /// <summary>
        ///向ArrayList添加ArrayList
        /// </summary>
        /// <returns>返回string</returns>
        public static ArrayList GetArrayListAdd(ArrayList arrTarget, ArrayList arrSource)
        {
            for (int N = 0; N <= arrSource.Count - 1; N++)
            {
                arrTarget.Add(arrSource[N]);
            }

            return arrTarget;
        }

        /// <summary>
        ///克隆指定字符的个数
        /// </summary>
        /// <param name="strString">指定字符</param>
        /// <param name="intLength">克隆个数</param>
        /// <returns>字符串</returns>
        public static string GetFileName(string strUrl)
        {
            string m_strUrl = strUrl;

            int intBegin = 0;
            int intEnd = m_strUrl.Length - 1;

            //替换成Window风格
            m_strUrl = m_strUrl.Replace("/", "\\");

            for (int N = 0; N <= m_strUrl.Length - 1; N++)
            {
                if (m_strUrl.Substring(N, 1) == "\\")
                {
                    intBegin = N + 1;
                }
            }

            for (int N = 0; N <= m_strUrl.Length - 1; N++)
            {
                if (m_strUrl.Substring(N, 1) == "?")
                {
                    intEnd = N - 1;
                }
            }

            string strFileName = strUrl;
            if ((intBegin < intEnd) && (intBegin >= 0) && (intEnd <= m_strUrl.Length - 1))
            {
                strFileName = m_strUrl.Substring(intBegin, intEnd - intBegin + 1);
            }

            return strFileName;
        }





        /// <summary>
        ///得到从页面返回Html Control组的数据集，并格式化为指定行格式
        /// </summary>
        /// <param name="ControlSign">要检测返回值的Html Control组的前缀标识名称</param>
        /// <param name="LinkSign">返回的值之间的连接字符串</param>
        /// <returns>返回Html Control组的指定行格式</returns>
        public static string GetRequestValueList(string ControlSign, string LinkSign)
        {
            string CControlValue;
            int SignLength, ControlLength, LoopNum;
            string TempCSign, TempResult;

            TempResult = "";
            LoopNum = 1;

            foreach (string RequestControlName in System.Web.HttpContext.Current.Request.Form)
            {
                SignLength = ControlSign.Length;
                ControlLength = RequestControlName.Length;
                if (ControlLength > SignLength)
                {
                    TempCSign = RequestControlName.Substring(0, SignLength);
                    if (TempCSign == ControlSign)
                    {
                        CControlValue = System.Web.HttpContext.Current.Request[RequestControlName];
                        if (CControlValue != "")
                        {
                            if (LoopNum == 1)
                            {
                                TempResult = CControlValue;
                                LoopNum = 2;
                            }
                            else
                            {
                                TempResult = TempResult + LinkSign + CControlValue;
                            }
                        }
                    }
                }
            }
            return TempResult;
        }

        /// <summary>
        ///得到从页面返回Html Control组的数据集，并格式化为指定行格式
        /// </summary>
        /// <param name="ControlSign">要检测返回值的Html Control组的前缀标识名称</param>
        /// <param name="LinkSign">返回的值之间的连接字符串</param>
        /// <returns>返回Html Control组的指定行格式</returns>
        public static string GetRequestNameList(string ControlSign, string LinkSign)
        {
            string CControlValue;
            int SignLength, ControlLength, LoopNum;
            string TempCSign, TempResult;

            TempResult = "";
            LoopNum = 1;

            foreach (string RequestControlName in System.Web.HttpContext.Current.Request.Form)
            {
                SignLength = ControlSign.Length;
                ControlLength = RequestControlName.Length;
                if (ControlLength > SignLength)
                {
                    TempCSign = RequestControlName.Substring(0, SignLength);
                    if (TempCSign == ControlSign)
                    {
                        CControlValue = System.Web.HttpContext.Current.Request[RequestControlName];
                        if (CControlValue != "")
                        {
                            if (LoopNum == 1)
                            {
                                TempResult = RequestControlName;
                                LoopNum = 2;
                            }
                            else
                            {
                                TempResult = TempResult + LinkSign + RequestControlName;
                            }
                        }
                    }
                }
            }
            return TempResult;
        }


        /// <summary>
        ///得到用加密后的字符串
        /// </summary>
        /// <param name="SourceString">指定字符串</param>
        /// <returns>返回加密后的字符串</returns>
        public static string GetEnCode(string SourceString, string Key)
        {
            return EncodeBase64(SourceString);
        }

        /// <summary>
        ///得到用解密后的字符串
        /// </summary>
        /// <param name="SourceString">指定字符串</param>
        /// <returns>返回解密后的字符串</returns>
        public static string GetDeCode(string SourceString, string Key)
        {
            return DecodeBase64(SourceString);
        }

        /// <summary>
        ///得到从页面返回Html Control组的数据集，并格式化为指定行格式
        /// </summary>
        /// <param name="ControlSign">要检测返回值的Html Control组的前缀标识名称</param>
        /// <param name="LinkSign">返回的值之间的连接字符串</param>
        /// <returns>返回Html Control组的指定行格式</returns>
        public static string GetCheckBoxListValueList(CheckBoxList chk, string LinkSign)
        {
            string strResult = "";

            for (int N = 0; N <= chk.Items.Count - 1; N++)
            {
                if (chk.Items[N].Selected == true)
                {
                    if (strResult != "")
                    {
                        strResult += LinkSign + chk.Items[N].Value;
                    }
                    else
                    {
                        strResult = chk.Items[N].Value;
                    }
                }
            }

            return strResult;
        }
        #region 获取星期
        /// <summary>
        /// 获取星期
        /// </summary>
        /// <param name="DateString"></param>
        /// <returns></returns>
        public static string GetWeek(string DateString)
        {
            string strResult = "";
            try
            {
                strResult = Convert.ToDateTime(DateString).DayOfWeek.ToString();
            }
            catch
            {
                strResult = "未知";
            }
            switch (strResult)
            {
                case "Monday":
                    strResult = "星期一";
                    break;
                case "Tuesday":
                    strResult = "星期二";
                    break;
                case "Wednesday":
                    strResult = "星期三";
                    break;
                case "Thursday":
                    strResult = "星期四";
                    break;
                case "Friday":
                    strResult = "星期五";
                    break;
                case "Saturday":
                    strResult = "星期六";
                    break;
                case "Sunday":
                    strResult = "星期七";
                    break;
            }
            return strResult;
        }
        #endregion

        #region 获取文件所在的虚拟目录
        /// <summary>
        /// 获取文件所在的虚拟目录
        /// </summary>
        /// <returns></returns>
        public static string getCurrentPath()
        {
            string filepath = System.Web.HttpContext.Current.Request.FilePath;
            filepath = filepath.Substring(0, filepath.LastIndexOf("/") + 1);
            return filepath;
        }
        #endregion

        #region 根据IP获取省市
        /// <summary>
        /// 根据IP获取省市
        /// </summary>
        public static string GetAddressByIp(string strIp)
        {
            string PostUrl = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=" + strIp;
            string res = GetDataByPost(PostUrl);//该条请求返回的数据为：res=1\t115.193.210.0\t115.194.201.255\t中国\t浙江\t杭州\t电信
            return getAreaInfoList(res);
        }

        /// <summary>
        /// Post请求数据
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string GetDataByPost(string url)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            string s = "anything";
            byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(s);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = requestBytes.Length;
            Stream requestStream = req.GetRequestStream();
            requestStream.Write(requestBytes, 0, requestBytes.Length);
            requestStream.Close();

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
            string backstr = sr.ReadToEnd();
            sr.Close();
            res.Close();
            return backstr;
        }

        /// <summary>
        /// 处理所要的数据
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public static string getAreaInfoList(string ipData)
        {

            string[] areaArr = new string[10];
            //取所要的数据，这里只取省市
            areaArr = ipData.Split('\t');
            return areaArr[4] + "省" + areaArr[5] + "市";
        }
        #endregion

        #region 验证身份证号码
        /// <summary>
        /// 验证身份证号码
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public static bool IsCard(string Id)
        {
            if (Id.Length == 18)
            {
                bool check = CheckIDCard18(Id);
                return check;
            }
            else if (Id.Length == 15)
            {
                bool check = CheckIDCard15(Id);
                return check;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 18位身份证验证
        /// </summary>
        /// <param name="Id">身份证号</param>
        /// <returns></returns>
        private static bool CheckIDCard18(string Id)
        {
            long n = 0;
            if (long.TryParse(Id.Remove(17), out n) == false || n < Math.Pow(10, 16) || long.TryParse(Id.Replace('x', '0').Replace('X', '0'), out n) == false)
            {
                return false;//数字验证
            }
            string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
            if (address.IndexOf(Id.Remove(2)) == -1)
            {
                return false;//省份验证
            }
            string birth = Id.Substring(6, 8).Insert(6, "-").Insert(4, "-");
            DateTime time = new DateTime();
            if (DateTime.TryParse(birth, out time) == false)
            {
                return false;//生日验证
            }
            string[] arrVarifyCode = ("1,0,x,9,8,7,6,5,4,3,2").Split(',');
            string[] Wi = ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2").Split(',');
            char[] Ai = Id.Remove(17).ToCharArray();
            int sum = 0;
            for (int i = 0; i < 17; i++)
            {
                sum += int.Parse(Wi[i]) * int.Parse(Ai[i].ToString());
            }
            int y = -1;
            Math.DivRem(sum, 11, out y);
            if (arrVarifyCode[y] != Id.Substring(17, 1).ToLower())
            {
                return false;//校验码验证
            }
            return true;//符合GB11643-1999标准
        }
        /// <summary>
        /// 15位身份证验证
        /// </summary>
        /// <param name="Id">身份证号</param>
        /// <returns></returns>
        private static bool CheckIDCard15(string Id)
        {
            long n = 0;
            if (long.TryParse(Id, out n) == false || n < Math.Pow(10, 14))
            {
                return false;//数字验证
            }
            string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
            if (address.IndexOf(Id.Remove(2)) == -1)
            {
                return false;//省份验证
            }
            string birth = Id.Substring(6, 6).Insert(4, "-").Insert(2, "-");
            DateTime time = new DateTime();
            if (DateTime.TryParse(birth, out time) == false)
            {
                return false;//生日验证
            }
            return true;//符合15位身份证标准

        }
        #endregion

        #region 根据身份证号，得到出生日期
        /// <summary>
        /// 根据身份证号，得到出生日期
        /// </summary>
        /// <param name="stridCard">身份证号</param>
        /// <returns>返回值</returns>
        public static string GetDateByCard(string stridCard)
        {
            string str_Temp = stridCard.Substring(6, 8);
            return DateTime.ParseExact(str_Temp, "yyyyMMdd", null).ToString("yyyy年MM月dd日");
        }
        #endregion

        #region 验证国内电话号码(包括手机 和座机号)
        /// <summary>
        /// 验证国内电话号码(包括手机 和座机号)
        /// </summary>
        /// <param name="validateString">待验证数据</param>
        /// <returns></returns>
        public static bool IsPhone(string validateString)
        {
            return RegexValidate("(^(0[0-9]{2,3}\\-)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?$)|(^((\\(\\d{3}\\))|(\\d{3}\\-))?(1[358]\\d{9})$)", validateString);
        }
        #endregion

        #region 验证用户姓名，（只能为4-16位）中英文
        /// <summary>
        /// 验证用户名，（只能为4-16位）中英文
        /// </summary>
        /// <param name="validateString"></param>
        /// <returns></returns>
        public static bool ckName(string validateString)
        {
            return RegexValidate("^[a-zA-Z\u4e00-\u9fa5]+$", validateString);
        }
        #endregion

        #region 验证邮箱地址
        /// <summary>
        /// 验证邮箱地址
        /// </summary>
        /// <param name="validateString"></param>
        /// <returns></returns>
        public static bool ckEmail(string validateString)
        {
            string pattern = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            return RegexValidate(pattern, validateString);
        }
        #endregion

        #region 字符串转BYTE[]]
        /// <summary>
        /// 字符串转BYTE[]]
        /// </summary>
        /// <param name="hexString"></param>
        /// <returns></returns>
        public static byte[] StringToByte(string hexString)
        {
            if (string.IsNullOrEmpty(hexString))
            {
                hexString = "00";
            }
            byte[] returnBytes = new byte[hexString.Length / 2];
            for (int i = 0; i < returnBytes.Length; i++)
                returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
            return returnBytes;
        }
        #endregion

        #region 读取byte[]并转化为图片
        /// <summary>
        /// 读取byte[]并转化为图片
        /// </summary>
        /// <param name="bytes">byte[]</param>
        /// <returns>Image</returns>
        public static System.Drawing.Image ByteToImage(byte[] streamByte)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte);
            System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
            return img;
        }
        #endregion

        #region 过滤不安全的字符串
        /// <summary>
        /// 过滤不安全的字符串
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string FilteSQLstr(string str)
        {
            if (str == string.Empty)
            {
                return string.Empty;
            }
            else
            {
                str = str.Replace("'", "");
                str = str.Replace("\"", "");
                str = str.Replace("&", "&amp");
                str = str.Replace("<", "&lt");
                str = str.Replace(">", "&gt");
                str = str.Replace("delete", "");
                str = str.Replace("update", "");
                str = str.Replace("insert", "");
                str = str.Replace(";", "；");
                str = str.Replace(",", ",");
                str = str.Replace("?", "?");
                str = str.Replace("<", "＜");
                str = str.Replace(">", "＞");
                str = str.Replace("(", "(");
                str = str.Replace(")", ")");
                str = str.Replace("@", "＠");
                str = str.Replace("=", "＝");
                str = str.Replace("+", "＋");
                str = str.Replace("*", "＊");
                str = str.Replace("&", "＆");
                str = str.Replace("#", "＃");
                str = str.Replace("%", "％");
                str = str.Replace("$", "￥");
                return str;
            }
        }
        #endregion

        #region 判断本地文件是否存在
        /// <summary>  
        /// 判断本地文件是否存在  
        /// </summary>  
        /// <param name="path"></param>  
        /// <returns></returns>  
        public static bool LocalFileExists(string filePath)
        {
            if (File.Exists(filePath))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion

        #region 清空客户端页面缓存
        /// <summary>
        /// 清空客户端页面缓存
        /// </summary>
        public static void ClearClientPageCache()
        {
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.Expires = 0;
            HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            HttpContext.Current.Response.AddHeader("pragma", "no-cache");
            HttpContext.Current.Response.AddHeader("cache-control", "private");
            HttpContext.Current.Response.CacheControl = "no-cache";
        }
        #endregion
    }
}
